package cn.hwl.springframework.context.support;

import cn.hwl.springframework.beans.BeansException;
import cn.hwl.springframework.beans.factory.ConfigurableListableBeanFactory;
import cn.hwl.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 * @author :  HuangWL
 * @date :    2022/4/28 15:52
 *   获取Bean工厂和加载资源
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {

    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() throws BeansException {
        DefaultListableBeanFactory beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    private  DefaultListableBeanFactory createBeanFactory(){
        return new DefaultListableBeanFactory();
    }

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
